<script>

var cod_select = "";
var todos = 1;
var cadeira = '<i>vazio</i>';

function saveComent()
{
	if(!cod_select)
	{
		msg({vmsg: "Selecione um item."});

		return false;
	}

	if(!$("#text_coment").val())
	{
		msg({vmsg: "Nenhum comentario informado."});

		return false;
	}
	
	$('#div_key').fadeOut();
	//alert(cod + $("#text_coment").val());
	
	if(cadeira != '<i>vazio</i>')
	{
		var str_coment = $("#text_coment").val() + 'Cadeira:' + cadeira;
	}
	else
	{
		var str_coment = $("#text_coment").val();
	}

	$.post("<?php echo $this->base; ?>/pedido/savecoment", {caf04_cadeira: cadeira, caf04_cod: cod_select, caf04_cod_item: '<?php echo $this->arr_coment[0]["caf04_cod_item"]; ?>', caf04_cod_prod: '<?php echo $this->arr_coment[0]["caf04_cod_prod"]; ?>', caf04_coment: str_coment}, function(){
		$('#coment_all').hide(); listProd();
	});
	msg({vmsg: "Comentario Salvo.",time: 3000});
}

function mostraMesa(un)
{
	$(".mesa_img").hide();
	$(".mesas_" + un).slideDown("fast");
}

function setCadeira(obj)
{
	cadeira = parseInt($(obj).html());
	
	$(obj).css("background-color", "red");

	proximoPasso();
}

function proximoPasso()
{
	$("#select_cadeira").hide();
	$("#select_produto").fadeIn("fast");
	$("#span_cadeira").html(cadeira);	

	$("#proximo_passo").click(function(){
		saveComent();
	});
}

function addTxtComent(txt)
{
	$("#text_coment").html(txt + ". ");
}

$(function(){
	var bool = "<?php echo $this->arr_coment; ?>";

	if(!bool)
	{
		$('#coment_all').hide();

		msg({vmsg: "Nenhum item adicionado."});
	}

	$(".sort").tablesorter({widgets: ['zebra']});
	
});

</script>

<?php echo $this->render("helpers/keyboard.phtml"); ?>

<div id="coment_all">
	<div class="blk_screen" style="opacity: 0.8; position: fixed; z-index: 980; width: 100%; height: 100%; background-color: white; top: 0; left: 0;"></div>
	<div class="ui-corner-all" style="border: 1px solid #B0ADAD; padding: 10px; background: white; position: fixed; z-index: 981; top: 30px; width: 500px; left: 50%; margin-left: -250px;">
		<div id="select_cadeira">
			<div id="titlekeyNum" class="ui-widget ui-corner-all" style="font-size: 22px; text-align: left; color: gray">
				1. Selecione uma cadeira.
			</div>
			<hr style="border-top: 1px dashed gray; margin-top: 5px; margin-bottom: 5px;" />
			<table align="center">
				<tr class="mesa_img">
					<td>
						<div style="position: absolute; padding-top: 10px; text-align: center; margin-top: 30px; margin-left: 20px; width: 40px; height: 30px;" onclick="setCadeira(this);">
							1
						</div>
						<div style="position: absolute; padding-top: 10px; text-align: center; margin-top: 110px; margin-left: 20px; width: 40px; height: 30px;" onclick="setCadeira(this);">
							2
						</div>
						<div style="position: absolute; padding-top: 10px; text-align: center; margin-top: 35px; margin-left: 180px; width: 40px; height: 30px;" onclick="setCadeira(this);">
							3
						</div>
						<div style="position: absolute; padding-top: 10px; text-align: center; margin-top: 110px; margin-left: 180px; width: 40px; height: 30px;" onclick="setCadeira(this);">
							4
						</div>
						<img src="<?php echo $this->base; ?>/public/images/mesa.png" />
					</td>
				</tr>
			</table>
		</div>
		<div id="select_produto" style="display: none;">
			<div id="titlekeyNum" class="ui-widget ui-corner-all" style="font-size: 22px; text-align: left; color: gray">
				2. Informe a descricao para cadeira: <span style="color: red;" id="span_cadeira"></span>.
			</div>
			<hr style="border-top: 1px dashed gray; margin-top: 5px; margin-bottom: 5px;" />
			<table id="prods" class="sort" width="100%" cellspacing="1" cellpadding="5" style="font-size: 15px;">
				<thead>
					<tr>
						<th style="background-image: none;">
							
						</th>
						<th>
							Produto
						</th>
						<th>
							Comentario
						</th>
						<th>
							Cadeira
						</th>
					</tr>
				</thead>
				<tbody>
				<?php 
				foreach ($this->arr_coment as $key => $val)
				{
					$cod = $val["caf04_cod"];
				?>
				<tr onclick="$('#<?php echo $cod; ?>_radio').click();">
					<td width="1%">
						<input type="radio" onclick="(cod_select = <?php echo $val["caf04_cod"]; ?>);" id="<?php echo $val["caf04_cod"]; ?>_radio" value="<?php echo $val["caf04_cod"]; ?>" name="prod_radio" />
					</td>
					<td width="1%">
						<?php echo "{$val["caf05_prod"]}({$val["caf05_car"]})"; ?>
					</td>
					<td>
						<i><?php echo $val["caf04_coment"]; ?></i>
					</td>
					<td>
						<i><?php echo $val["caf04_cadeira"]; ?></i>
					</td>
				</tr>
				<?
				}
				?>
				</tbody>
			</table>
			<hr style="border-top: 1px dashed gray; margin-top: 5px; margin-bottom: 5px;" />
			<div style="padding: 5px 0 5px 0; text-align: center;">
				<a style="padding: 10px;" onclick="addTxtComent('Com Gelo');" href="javascript:;">Com Gelo</a>|<a style="padding: 10px;" onclick="addTxtComent('Sem Gelo');" href="javascript:;">Sem Gelo</a>
			</div>
			<hr style="border-top: 1px dashed gray; margin-top: 5px; margin-bottom: 5px;" />
			<textarea onclick="showKeyboard();" id="text_coment" class="ui-corner-all" style="width: 497px; border: 1px solid gray;" rows="5" cols=""></textarea>
		</div>
		<hr style="border-top: 1px dashed gray; margin-top: 5px; margin-bottom: 5px;" />
		<div>
			<div class="button ui-corner-all" onclick="$('#coment_all').hide(); $('#div_key').fadeOut();" style="text-align: center; float: left; padding: 20px; width: 201px;">
				<b>Cancelar</b>
			</div>
			<div id="proximo_passo" class="button ui-corner-all" onclick="proximoPasso();" style="text-align: center; padding: 20px; margin-left: 256px; width: 201px;">
				<b>Proximo >></b>
			</div>
		</div>
	</div>
</div>